package logic

import (
	"context"
	"dayrpc/dayrpc"
	"dayrpc/internal/svc"
	"dayrpc/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLogic {
	return &UpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateLogic) Update(in *dayrpc.RequestUpdate) (*dayrpc.ResponseUpdate, error) {
	// todo: add your logic here and delete this line
	data := mysql.Dao{
		NameID: int(in.NameID),
		Name:   in.Name,
		Qu:     in.Qu,
		Zhi:    in.Zhi,
		Ke:     in.Ke,
	}
	mysql.DB.Where("NameID=?", in.NameID).Updates(&data)
	return &dayrpc.ResponseUpdate{
		NameID: in.NameID,
	}, nil
}
